package XMLread;

import java.util.ArrayList;
import android.util.SparseArray;
import com.google.android.maps.GeoPoint;


public class Building {
	private String buildingID;
	private ArrayList<Floor> floors;
	private SparseArray<Floor> floorArray;
	private ArrayList<String> exitFloors;


	public Building(){
		buildingID = "";
		floors = new ArrayList<Floor>();
		floorArray = new SparseArray<Floor>();
		exitFloors = new ArrayList<String>();
	}

	public Building(ArrayList<Classroom> listOfClassrooms) {
		buildingID = "";
		floors = new ArrayList<Floor>();
		floorArray = new SparseArray<Floor>();
	}

	public String getBuildingID(){
		return buildingID;
	}

	public void setBuildingID(String id){
		buildingID = id;
	}

	public ArrayList<Floor> getFloors(){
		return floors;
	}

	public void addEntity(Floor landing) {
		floors.add(landing);
		boolean addedExit = false;
		//	floorArray.put(Integer.valueOf(landing.getID()), landing);
		for(Hallway h : landing.getHallways()){
			for(Object o : h.getEntities()){
				if(o instanceof Exit){
					exitFloors.add(landing.getID()+"");
					addedExit = true;
					break;
				}
			}
			if(addedExit)
				break;
		}
	}

	public ArrayList<String> getExitFloors(){
		return exitFloors;
	}

	public Stairwell containsStairwellsAtLoc(GeoPoint gp){

		for(Floor f : floors){
			for(Hallway h : f.getHallways()){
				for(Object o : h.getEntities()){
					if(o instanceof Stairwell && ((Stairwell) o).getGeopoint().equals(gp) && 
							exitFloors.contains(((Stairwell) o).getCurrentFloor()+"")){
						return (Stairwell) o;
					}
				}
			}
		}
		return null;
	}

	public boolean weOnExitFloor(Stairwell start) {
		String currentFloor = start.getCurrentFloor()+"";
		return exitFloors.contains(currentFloor);
	}

}
